﻿using System;
using System.Collections.Generic;

using System.Text;

namespace db
{
   public class dbopt
    {
        public static string getAValue(string sql,string fld)
        {   string rtn="";
            db.DbHelper c = new db.DbHelper();
            System.Data.DataTable dt = c.RunQuery(sql);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {

                   rtn= ""+dt.Rows[0][fld];
                }
 
            }
            return rtn;
        }
        ///*<li><a href="url?id=x">content</a></li>
        public static string getLi(string sql, string url,string keyfield,string dispfield,int lines )
        {
            StringBuilder rtn = new StringBuilder();
            db.DbHelper c = new db.DbHelper();
            System.Data.DataTable dt = c.RunQuery(sql);

            if (dt == null || dt.Rows.Count <= 0)
                rtn.AppendLine("<li>没有数据</li>");
            else
            {
                if (lines > dt.Rows.Count) lines = dt.Rows.Count;
                for (int i = 0; i < lines; i++)
                    rtn.AppendLine(" <li><a href=\"" + url + "?" + keyfield + "=" + dt.Rows[i][keyfield] + "\">" + dt.Rows[i][dispfield] + "</a></li>");
            }
            return rtn.ToString();
        }
        /*<li><a href="url?id=x">content</a></li>
                         <%
                     sql = "select * from zhifadw ";
                     System.Data.DataTable dt = new db.DbHelper().RunQuery(sql);
                     if (dt == null || dt.Rows.Count <= 0)
                     {%>
                        <li>没有数据</li>   
                         <%}
                     else
                         for (int i = 0; i < dt.Rows.Count; i++)
                             {%>
                              <li><a href="index.aspx?id=<%=dt.Rows[i]["zfdwid"] %>"><%=dt.Rows[i]["zfdwname"]%></a></li>
                <%} %>
        
         */
    }
}
